package com.wowo.aop.calc;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//@Component
//@Aspect
public class LogAspect {
    //@Pointcut("execution(* com.wowo.aop.calc.*.*(..))")
    public void pref(){}
    //@Before("pref()")
    public void start(JoinPoint joinPoint){
        String str = "";
        if("add".equals(joinPoint.getSignature().getName()))str="+";
        if("sub".equals(joinPoint.getSignature().getName()))str="-";
        System.out.println("开始计算:"+joinPoint.getArgs()[0]+str+joinPoint.getArgs()[1]);
    }
//    @Around("pref()")
//    public Object aroundCalc(ProceedingJoinPoint pjp) throws Throwable {
//        Object obj;
//        if(pjp.getSignature().getName()=="add"){
//            System.out.println("开始计算"+pjp.getArgs()[0]+"+"+pjp.getArgs()[1]);
//            obj = pjp.proceed();
//            System.out.println("计算结果="+obj);
//        }else{
//            System.out.println("开始计算"+pjp.getArgs()[0]+"-"+pjp.getArgs()[1]);
//            obj = pjp.proceed();
//            System.out.println("计算结果"+obj);
//        }
//        return obj;
//    }
    //value = perf()
    //@AfterReturning(pointcut = "pref()",returning = "result")
    public void after(Object result){
        System.out.println("计算结果是:"+result);
    }
}
